package com.stars.home.vmodel

import android.app.Activity
import android.app.Application
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.stars.home.model.ServiceList
import com.stars.home.model.User
import com.stars.home.utils.net.NetEngine
import com.trailer.base.base.BRepository
import com.trailer.base.base.BViewModel
import kotlinx.coroutines.launch

class SetUpVModel(application: Application) : BViewModel<BRepository>(application) {


    var user = MutableLiveData<User>()
    var list = MutableLiveData<List<ServiceList>>()


    fun getUserInfo() {
        viewModelScope.launch {
            var it = repository().lreq { NetEngine.service.getUser() }
            if (it.ok()) {
                user.value = it.data

            } else {
            }
        }
    }

    fun getService() {
        viewModelScope.launch {
            var it = repository().lreq { NetEngine.service.listPlatformService() }
            if (it.ok()) {
                list.value = it.data
            }
        }
    }

    fun toSubmit(remark: String, technicianServiceJson: String) {

        viewModelScope.launch {
            var it = repository().lreq {
                NetEngine.service.serviceUpdateStatus(
                    remark,
                    technicianServiceJson
                )
            }
            if (it.ok(true)) {
                (repository().context as Activity).finish()
            }
        }

    }


}



